package person.wangchen11.qeditor;

import person.wangchen11.editor.edittext.MyEditText;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
	MyEditText mMyEditText;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		configAllView(findViewById(R.id.main_layout));
		mMyEditText=(MyEditText) findViewById(R.id.myEditText1);
	}

	private void configAllView(View view){
		if(view instanceof ViewGroup )
		{
			int count = ((ViewGroup)(view)).getChildCount();
			for(int i=0;i<count;i++){
				configAllView(((ViewGroup)(view)).getChildAt(i));
			}
		}
		
		if( view instanceof Button ){
			view.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button1:
			mMyEditText.setCursor(0);
			break;
		case R.id.button2:
			mMyEditText.setCursor(mMyEditText.getText().length());
			break;
		case R.id.button3:
			mMyEditText.performContextMenuAction(android.R.id.selectAll);
			break;
		case R.id.button4:
			mMyEditText.performContextMenuAction(android.R.id.copy);
			break;
		case R.id.button5:
			mMyEditText.performContextMenuAction(android.R.id.paste);
			break;

		default:
			break;
		}
	}

}
